package com.situ.company.project.service.impl;

import java.util.List;

import com.situ.company.department.model.DepartmentModel;
import com.situ.company.project.dao.IProjectDao;
import com.situ.company.project.dao.impl.ProjectDaoImpl;
import com.situ.company.project.model.ProjectModel;
import com.situ.company.project.service.IProjectService;

public class ProjectServiceImpl implements IProjectService{

	private IProjectDao dao = new ProjectDaoImpl();
	@Override
	public String insert(ProjectModel model) {
		if(selectModel(model) == null) {
			Integer res=dao.insert(model);
			return res==null?null:res.toString();
		}
		return "repeat";
	}

	@Override
	public String delete(ProjectModel model) {
		Integer res=dao.delete(model);
		return res==null?null:res.toString();
	}

	@Override
	public Integer update(ProjectModel model) {
		return dao.updateAll(model);
	}

	@Override
	public List<ProjectModel> selectList(ProjectModel model) {
		String code=model.getCode();
		model.setCode(code==null?"%":"%"+code+"%");
		String name=model.getName();
		model.setName(name==null?"%":"%"+name+"%");
		return dao.selectList(model);
	}

	@Override
	public ProjectModel selectModel(ProjectModel model) {
		return dao.selectModel(new ProjectModel(model.getCode()));
	}

	@Override
	public Integer selectCount(ProjectModel model) {
		ProjectModel m1=new ProjectModel();
		String code=model.getCode();
		m1.setCode(code==null?"%":"%"+code+"%");
		String name=model.getName();
		m1.setName(name==null?"%":"%"+name+"%");
		return dao.selectCount(m1);
	}

	

}
